class audio:

  def __init__(self,filename):
    self.title = "unkown"
    self.album = "unkown"
    self.artist = "unkown"
    self.tracknumber = 0
    self.build(filename)
    self.bitrate = 0
  
  def build(self,filename):
    self.filename = filename
    self.filetype = unicode(filename.split(".")[-1])
    try:
      if self.filetype in ("mp3"):
        from mutagen.easyid3 import EasyID3
        audio = EasyID3(filename)
        self.title = audio["title"][0]
        self.artist = audio["artist"][0]
        self.album = audio["album"][0]
        self.tracknumber = audio["albumsort"][0]
      if self.filetype in ("flac"):
        from mutagen.flac import FLAC
        audio = FLAC(filename)
        self.title = audio["title"][0]
        self.artist = audio["artist"][0]
        self.album = audio["album"][0]
        self.tracknumber = audio["albumsort"][0]
    except KeyError:
      pass #This is so it doesn't break on information it doesn't have
    except:
      print "error proccessing file: " + filename

  def to_db(self):
    return (self.filename,self.filetype,self.title,self.artist,self.album,self.tracknumber,self.bitrate)

